# 计算机视觉的编码颜色选择

# 导入所需包
from functools import reduce
import matplotlib.pyplot as plt
import matplotlib.image as mping
import numpy as np

# 传入图片
img = mping.imread('test1.jpg')


# 输出图片格式与大小
print('This image is: ', type(img), 'with dimensions: ', img.shape)

# 复制图像的宽高
y = img.shape[0]
x = img.shape[1]

# 复制颜色选择
color_select = np.copy(img)
# print(color_select)

# 定义颜色选择阈值 此向量包含了我们选择中允许的(R, G, B)的最小值
red_threshold = 200
green_threshold = 200
blue_threshold = 200
rgb_threshold = [red_threshold, green_threshold, blue_threshold]

# 识别阈值的像素
thresholds = (img[:,:,0] < rgb_threshold[0]) \
            | (img[:,:,1] < rgb_threshold[1]) \
            | (img[:,:,2] < rgb_threshold[2])
color_select[thresholds] = [0, 0, 0]

# 输出图象
plt.imshow(color_select)
plt.show()
